home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-19 | 3.4 KB | 154 lines | [TEXT/MPS ] |
- /*
- Windoid.cp
-
- Class that implements a "windoid" floating palette type window.
-
- Superclass: WindowDefinition.
- */
-
- #ifndef __WINDOID__
- #include "Windoid.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- void Windoid::CalcRgns()
- {
- // compute the content region of the window.
- Rect itsPortRect = itsWindow->port.portRect;
- OffsetRect(&itsPortRect, -itsWindow->port.portBits.bounds.left, -itsWindow->port.portBits.bounds.top);
- RectRgn(itsWindow->contRgn, &itsPortRect);
-
- // compute the struct region.
- InsetRect(&itsPortRect, -1, -1);
- itsPortRect.top -= 10;
- RectRgn(itsWindow->strucRgn, &itsPortRect);
- itsPortRect.left++; itsPortRect.top++;
- OffsetRect(&itsPortRect, 1, 1);
- RgnHandle tmpRgn = NewRgn();
- RectRgn(tmpRgn, &itsPortRect);
- UnionRgn(tmpRgn, itsWindow->strucRgn, itsWindow->strucRgn);
- DisposeRgn(tmpRgn);
- }
-
- void Windoid::DrawFrame()
- {
- // remember current penstate.
- PenState oldPen;
- GetPenState(&oldPen);
-
- // compute "hot" rectangles.
- CalcRects();
-
- // draw frame around content region.
- PenSize(1, 1);
- FrameRect(&itsFrame);
-
- // draw drop shadow.
- MoveTo(itsFrame.left + 3, itsFrame.bottom);
- LineTo(itsFrame.right, itsFrame.bottom);
- LineTo(itsFrame.right, itsFrame.top - 9);
-
- // draw the drag bar.
- Pattern itsDragBarPat;
- unsigned long grayBits;
- if(itsDragRect.left & 1)
- grayBits = 0xAA00AA00;
- else
- grayBits = 0x55005500;
- if(itsDragRect.top & 1)
- grayBits >>= 8;
- ((long*)itsDragBarPat)[0] = grayBits;
- ((long*)itsDragBarPat)[1] = grayBits;
- FillRect(&itsDragRect, itsDragBarPat);
- FrameRect(&itsDragRect);
-
- // draw go-away box if there is one.
- if (itsWindow->goAwayFlag) {
- InsetRect(&itsGoAwayBox, -1, -1);
- EraseRect(&itsGoAwayBox);
- InsetRect(&itsGoAwayBox, 1, 1);
- FrameRect(&itsGoAwayBox);
- }
-
- // preserve old font settings.
- short txFont = qd.thePort->txFont;
- short txSize = qd.thePort->txSize;
-
- // set new font style.
- TextFont(3);
- TextSize(9);
-
- Rect txtRect = itsDragRect;
- InsetRect(&txtRect, 0, 1);
- HLock((Handle)itsWindow->titleHandle);
- short itsWidth = StringWidth(*itsWindow->titleHandle);
- txtRect.left += (itsFrame.right - itsFrame.left - itsWidth)/2 - 2;
- txtRect.right = txtRect.left + itsWidth + 2;
- EraseRect(&txtRect);
- MoveTo(itsFrame.left + (itsFrame.right - itsFrame.left - itsWidth)/2, itsFrame.top - 1);
- DrawString(*itsWindow->titleHandle);
- HUnlock((Handle)itsWindow->titleHandle);
-
- TextFont(txFont);
- TextSize(txSize);
-
- SetPenState(&oldPen); // restore old penstate.
- }
-
- void Windoid::DrawGoAwayBox()
- {
- // compute "hot" rectangles.
- CalcRects();
- InvertRect(&itsGoAwayBox);
- }
-
- void Windoid::DrawGIcon()
- {
- }
-
- void Windoid::DrawGrowImage(Rect& growRect)
- {
- }
-
- long Windoid::Hit(Point& whereHit)
- {
- if(PtInRgn(whereHit, itsWindow->strucRgn)) {
- // compute "hot" rectangles.
- CalcRects();
- if(PtInRect(whereHit, &itsDragRect)) {
- if(PtInRect(whereHit, &itsGoAwayBox))
- return wInGoAway;
- return wInDrag;
- }
- if(PtInRgn(whereHit, itsWindow->contRgn))
- return wInContent;
- }
- return wNoHit;
- }
-
- // private methods.
-
- void Windoid::CalcRects()
- {
- itsFrame = (**itsWindow->contRgn).rgnBBox;
- InsetRect(&itsFrame, -1, -1);
-
- itsDragRect = itsFrame;
- itsDragRect.bottom = itsDragRect.top + 1;
- itsDragRect.top -= 10;
-
- if(itsWindow->goAwayFlag) {
- itsGoAwayBox = itsDragRect;
- itsGoAwayBox.left += 8;
- itsGoAwayBox.top += 2;
- itsGoAwayBox.right = itsGoAwayBox.left + 7;
- itsGoAwayBox.bottom = itsGoAwayBox.top + 7;
- }
- }